package com.baitiaojun.system.admin.service.permission.impl;

import com.baitiaojun.common.enums.impl.UserTypeEnum;
import com.baitiaojun.system.admin.mapper.permission.RoleMapper;
import com.baitiaojun.system.admin.pojo.SysRoleDO;
import com.baitiaojun.system.admin.service.permission.RoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Set;

@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, SysRoleDO> implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    /**
     * 根据用户id获取用户角色
     * @param userId
     * @return
     */
    @Override
    public Set<SysRoleDO> getRolesByUserId(String userId) {
        return roleMapper.selectRolesByUserId(userId);
    }

    @Override
    public boolean isAnySupperAdmin(Long[] roleIds) {
        return Arrays.stream(roleIds)
                .anyMatch(roleId -> roleId.equals(Long.valueOf(UserTypeEnum.ADMIN.getCode())));
    }
}
